<?php
/**
 * Created by PhpStorm.
 * User: denh
 * Date: 16/7/14
 * Time: 下午5:06
 */
require_once ADMIN_PATH . '../bs/bs.message.php';
//require_once ADMIN_PATH . '../bs/wxNews/Conference.php';
require_once ADMIN_PATH . '../bs/wxNews/Task.php';
require_once ADMIN_PATH . '../bs/wxNews/Course.php';

class CliController extends BaseController {

    public $id = '';
    public $limit = 1000;

    function __construct($m = DEFAULT_CONTROLLER, $a = DEFAULT_METHOD) {
        parent::__construct($m, $a);
        if (php_sapi_name() != 'cli') {
            exit('请在命令行下执行');
        }
        global $argv;
        isset($argv[3]) && $this->id = $argv[3];
        isset($argv[4]) && $this->limit = $argv[4];
        logger()->logInfo("argv:". var_export($argv, true));
    }

    function test() {
        echo 'ceshi';
    }

    #课程消息
    function courser_msg() {
        $bm = new C发微信消息();
        $bm->fc发送图文消息_所有用户('视频课程', $this->id, '', $this->limit, NewsCount_PerProcess);

    }

    #新的课程消息
    function course_msg() {
        $bs = new \bs\wxNews\Course_1('course_notice_1', $this->id);
        $bs->sendToAllUser($this->limit, NewsCount_PerProcess);
    }

    #资讯消息
    function zixun_msg() {
        $bm = new C发微信消息();
        $bm->ff发送咨询信息($this->id, '', $this->limit, NewsCount_PerProcess);
    }

    #投票消息
    function vote_msg() {
        $bm = new C发微信消息();
        $bm->send_vote($this->id, '', $this->limit, NewsCount_PerProcess);
    }

    //推送会议视频消息
    function meet_video_msg() {
        $bm = new C发微信消息();
        $bm->send_meet_video_message($this->id, '', $this->limit, NewsCount_PerProcess);
    }

    //会议消息
    function meet_msg() {
        $news = new \bs\wxNews\Conference('meet', $this->id);
        $news->sendToAllUser($this->limit, NewsCount_PerProcess);
    }

    //自定义作业消息
    function task_msg() {
        $task =  new \bs\wxNews\Task('task', $this->id);
        $task->sendToPartUser($this->limit, NewsCount_PerProcess);
    }

    #发送资讯消息
    function send_zixun_news() {
        logger()->logInfo("===call send_zixun_news===");
        $doInformation = new Do咨询信息();
        $doInformation->set_发送('未发送');
        $doInformation->set_发布时间(date("Y-m-d"));
        if (!$doInformation->where($doInformation->data)->row()) {
            logger()->logInfo("群发资讯消息 今天没有要发送的资讯 do:".var_export($doInformation, true));
            return false; #今天没有要发送的资讯
        }

        $doDetail = new Do咨询详情();
        $doDetail->set_咨询id($doInformation->get_id());
        if (!$doDetail->where($doDetail->data)->count()) {
            logger()->logInfo("群发资讯消息 该资讯的图文内容为空 id:".$doInformation->get_id());
            return false; #该资讯的图文内容为空
        }

        $url = $this->url('push_information',
            'push_message', array('id' => $doInformation->get_id(), 'cli' => '27tjdhs2323'));
        Tools::curl_get_contents($url, 120);

        logger()->logInfo("群发资讯消息 id：".$doInformation->get_id());
    }
}